package main

import (
	"fmt"
	"time"
)

var locales map[string]map[string]string

func main() {
	locales = make(map[string]map[string]string, 2)
	en := make(map[string]string, 10)
	en["pea"] = "pea"
	en["bean"] = "bean"
	en["how old"] = "i am %d years old\n"
	en["time_zone"]="America/Chicago"
	en["date_format"]="%Y-%m-%d %H:%M:%S"
	locales["en"] = en

	cn := make(map[string]string, 10)
	cn["pea"] = "豌豆"
	cn["bean"] = "毛豆"
	cn["how old"] = "我今年 %d 岁了\n"
	cn["time_zone"]="Asia/Shanghai"
	cn["date_format"]="%Y 年%m 月%d 日 %H 时%M 分%S 秒"
	locales["zh"] = cn

	fmt.Println("初始化数据完成......")

	lang := "zh"
	fmt.Println(msg(lang, "pea"))
	fmt.Println(msg(lang, "bean"))
	lang = "en"
	fmt.Printf(msg(lang,"how old"),15)
	loc,_:=time.LoadLocation(msg(lang,"time_zone"))
	t:=time.Now().In(loc)
	fmt.Println(t.Format(time.RFC3339))
}

func msg(locale, key string) string {
	if v, ok := locales[locale]; ok {
		if v2, ok := v[key]; ok {
			return v2
		}
	}
	return ""
}
